﻿Public Partial Class CauseOfRemark
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            If Not (Session("RemarkEdit") Is Nothing) Then
                ViewState("RowEdit") = Session("RemarkEdit")
                Dim dt As DataTable = Session("Remark")
                txtRemark.Text = dt.Rows(ViewState("RowEdit")).Item("Remark")
                'txtDelayTime.Text = dt.Rows(ViewState("RowEdit")).Item("Delay_Time")
            Else
                ViewState("RowEdit") = ""
            End If
        End If
    End Sub

    Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Session("RemarkEdit") = Nothing
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalPopupRemark('N');", True)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If (txtRemark.Text.Trim() = "") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการระบุข้อความ !!');", True)
            Exit Sub
        End If



        Dim dt As DataTable = Session("Remark")
        If (ViewState("RowEdit") & "" = "") Then
            'ใหม่
            Dim dr As DataRow = dt.NewRow
            dr.Item("Remark") = txtRemark.Text
            dt.Rows.Add(dr)
            dt.AcceptChanges()
        Else
            'เก่า
            Dim index As Integer = ViewState("RowEdit")
            dt.Rows(index).Item("Remark") = txtRemark.Text
            dt.AcceptChanges()
        End If
        Session("Remark") = dt
        Session("RemarkEdit") = Nothing
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalPopupRemark('S');", True)
    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub
End Class